#coding=utf-8
'''
时间处理相关操作

Created on 2010-8-17

@author: lijun
'''

import time
import datetime


def Str2DateTime(dateStr):
    assert dateStr 
    # 格式为 2009-10-10 12:33:35
    try:
        t = time.strptime(dateStr, "%Y-%m-%d %X")
        dateTime = datetime.datetime(*t[:6])
    except Exception,e:
        raise
    
    return dateTime
    
def DateTime2Str(date):
    assert date 
    try:
        t = date
        dateStr = '%04d-%02d-%02d %02d:%02d:%02d' % (t.year, t.month, t.day,
                                                    t.hour, t.minute, t.second)
        return dateStr
    except Exception,e:
        raise 
    return      


def CheckDateStr(dateStr):
    '''检查时间字符串是否有效
    '''
    assert dateStr
    isValid = False
    try:
        Str2DateTime(dateStr)
    except Exception,ex:
        isValid = False
    else:
        isValid = True
    return isValid
    
    
    
if __name__ == '__main__':
    d1 = datetime.datetime.now()
    pass
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    